package com.kcsj.demo.Controller;

import com.kcsj.demo.Mapper.UserMapper;
import com.kcsj.demo.Module.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    UserMapper userMapper;
    @GetMapping("/user")
    public String userController(Map<String,Object> map){
        map.put("list",userMapper.list());
        return "user";
    }
    @PostMapping("/PostUser")
    public String userInsert(@RequestParam(name = "user_name") String userName,
                             @RequestParam(name = "commodity_name") String commodityName,
                             @RequestParam(name = "commodity_number") Integer commodityNumber){
        User user = new User();
        user.setName(userName);
        user.setCompany(commodityName);
        user.setTelephoneNumber(commodityNumber);
        userMapper.insert(user);
        return "jump";
    }
    @PostMapping("/PostUserDelete")
    public String UserDelete(
            @RequestParam(name = "user_delete") String username
    ){
        userMapper.delete(username);
        return "jump";
    }
}
